package com.pda.smallbug.myapplication;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import org.xutils.http.RequestParams;
import org.xutils.x;

import de.greenrobot.event.EventBus;

/**
 * Created by Administrator on 2017/6/28.
 */

public class SystemAcitvity extends Activity{
    private EditText editText;
    private Button confirm;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.system);
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        editText=(EditText) findViewById(R.id.editText);
        String url=MyApplication.mySharedPreferences.getString("url","");
        if (url.isEmpty()){

        }else {
            editText.setText(url.substring(7,url.length()-1));
        }
        confirm=(Button)findViewById(R.id.confirm);
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (editText.getText().toString().isEmpty()){
                    Toast.makeText(SystemAcitvity.this,"请填写服务器地址",Toast.LENGTH_SHORT).show();
                }else {
                    SharedPreferences.Editor edit = MyApplication.mySharedPreferences.edit();
                    edit.putString("url","http://"+editText.getText().toString()+"/");
                    MyApplication.url="http://"+editText.getText().toString()+"/";
                    edit.commit();
                    Toast.makeText(SystemAcitvity.this,"设置成功",Toast.LENGTH_SHORT).show();
                    EventBus.getDefault().post(new MyEvent(0,""));
                    finish();
                }
            }
        });
    }

}
